#include "GameTimer.h"
#include "TimeController.h"
#include "Animation.h"
#include "AnimationSprite.h"
#include "ResMgr.h"
#include "Vector.h"

GameTimer::GameTimer(float sumTime, int x, int y, int width, int height)
:Object(x, y, width, height, 0)
{
	this->sumTime = sumTime;
	Animation* ani = new Animation(0);
	ani->GenerateAuto(ResMgr::GetInstance()->GetTexture(TID_LOCK), 
		SPRITE_WIDTH, SPRITE_HEIGHT, 1, 0, 0, 0);
	aniSprite->AddAnimation(ani);
	aniSprite->SetCurAnimation(0);
	Reset();
}
GameTimer::~GameTimer(){}

void GameTimer::IncreaseTime(float deltaTime)
{
	remainTime += deltaTime;
}

void GameTimer::DecreaseTime(float deltaTime)
{
	remainTime -= deltaTime;
}

bool GameTimer::IsTimeOut()
{
	if(remainTime > 0) 
		return false;
	else return true;
}

void GameTimer::Reset()
{
	this->remainTime = sumTime;
}

void GameTimer::Update()
{
	remainTime -= TimeController::GetInstance()->GetDtInSecond();
}

void GameTimer::Render()
{
	aniSprite->Render(pos->x, pos->y, 
		(float)width/(float)SPRITE_WIDTH*remainTime/sumTime, (float)height/SPRITE_HEIGHT, 0.0f, 1.0f, 1.0f);
}